package com.vanzo.talkie2;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;

/**
 * Created by tisen on 2018/1/17.
 */

public class ImageSwitch {
    private Activity activity;
    private ColorTextView textView;
    private ImageView imageView;

    private boolean default_value;

    private int trueImgSrc;
    private int falseImgSrc;
    private int textTitle;
    private int trueTextValue;
    private int falseTextValue;


    public ImageSwitch(Activity activity, ColorTextView textView, final ImageView imageView) {
        this.activity = activity;
        this.textView = textView;
        this.imageView = imageView;
        this.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setValue(!default_value);
            }
        });
    }

    public void setImgSrc(int trueImgSrc, int falseImgSrc) {
        this.trueImgSrc = trueImgSrc;
        this.falseImgSrc = falseImgSrc;
    }

    public void setTextValue(int textTitle, int trueTextValue, int falseTextValue) {
        this.textTitle = textTitle;
        this.trueTextValue = trueTextValue;
        this.falseTextValue = falseTextValue;
    }

    public void setValue(boolean value) {
        this.default_value = value;
        imageView.setImageResource(value ? trueImgSrc : falseImgSrc);
        textView.setText(textTitle, value ? trueTextValue : falseTextValue);
    }

    public boolean getValue() {
        return this.default_value;
    }

    public void setEnabled(boolean enabled) {
        this.textView.setEnabled(enabled);
        this.imageView.setEnabled(enabled);
    }
}
